package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetMealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController

@Slf4j
@RequestMapping("/admin/setmeal")
@Api("套餐相关接口")
public class SetmealController {
    @Autowired
    private SetMealService setMealService;

    //新增套餐
    @ApiOperation("新增套餐")
    @PostMapping
    public Result<SetmealVO> save(@RequestBody SetmealDTO setmealDTO) {
        log.info("新增套餐,{}", setmealDTO);
        setMealService.save(setmealDTO);
        return Result.success();
    }

    //套餐分页查询
    @ApiOperation("套餐分页")
    @GetMapping("/page")
    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO) {
        log.info("套餐分页");
        PageResult pageResult = setMealService.page(setmealPageQueryDTO);
        return Result.success(pageResult);
    }

    //删除套餐
    @ApiOperation("删除套餐")
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids) {
        log.info("删除套餐:{},", ids);
        setMealService.deleteBatch(ids);
        return Result.success();
    }

    //根据id查询套餐
    @ApiOperation("根据id查询套餐")
    @GetMapping("/{id}")
    public Result<SetmealVO> selectById(@PathVariable Long id){
       SetmealVO setmealVO= setMealService.selectById(id);
       return Result.success(setmealVO);
    }
    //修改套餐
    @ApiOperation("修改套餐")
    @PutMapping
    public Result update(@RequestBody SetmealDTO setmealDTO){
        log.info("修改套餐");
        setMealService.update(setmealDTO);
        return Result.success();
    }

    //套餐的起售和停售
    @ApiOperation("套餐的起售和停售")
    @PostMapping("/status/{status}")
    public Result StartOrStop(@PathVariable Long status,Long id){
        setMealService.StartOrStop(status,id);
        return Result.success();
    }
}
